<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Nginx反向代理完全指南</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 1.5rem;
            overflow-x: auto;
            position: relative;
        }
        
        .code-block::before {
            content: attr(data-lang);
            position: absolute;
            top: 0.5rem;
            right: 0.5rem;
            font-size: 0.75rem;
            color: #858585;
            text-transform: uppercase;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 12px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            font-size: 24px;
            margin-bottom: 1rem;
        }
        
        .section-divider {
            height: 2px;
            background: linear-gradient(to right, transparent, #e0e0e0, transparent);
            margin: 3rem 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center animate-fadeInUp">
            <h1 class="text-5xl md:text-6xl font-bold mb-6">
                <i class="fas fa-server mr-4"></i>Nginx反向代理
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">掌握现代Web架构的核心技术</p>
            <div class="flex justify-center space-x-4">
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                    <i class="fas fa-shield-alt mr-2"></i>安全隔离
                </span>
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                    <i class="fas fa-balance-scale mr-2"></i>负载均衡
                </span>
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                    <i class="fas fa-tachometer-alt mr-2"></i>性能优化
                </span>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-6 py-12">
        <!-- Introduction Card -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12 card-hover">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">N</span>ginx反向代理是指Nginx作为中介接收客户端的请求，并将这些请求转发到后端服务器进行处理，然后将后端服务器的响应返回给客户端。与传统的正向代理不同，反向代理是将请求代理到内网或不同服务器上，隐藏了实际处理请求的服务器。反向代理通常用于负载均衡、提高性能、安全性和高可用性等场景。
            </p>
        </div>

        <!-- Concept Visualization -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 text-gradient">工作原理可视化</h2>
            <div class="mermaid">
                graph LR
                    A[客户端] -->|请求| B[Nginx反向代理]
                    B -->|转发请求| C[后端服务器1]
                    B -->|转发请求| D[后端服务器2]
                    B -->|转发请求| E[后端服务器3]
                    C -->|响应| B
                    D -->|响应| B
                    E -->|响应| B
                    B -->|返回响应| A
                    
                    style A fill:#f9f,stroke:#333,stroke-width:2px
                    style B fill:#667eea,stroke:#333,stroke-width:2px,color:#fff
                    style C fill:#9f9,stroke:#333,stroke-width:2px
                    style D fill:#9f9,stroke:#333,stroke-width:2px
                    style E fill:#9f9,stroke:#333,stroke-width:2px
            </div>
        </div>

        <!-- Basic Concepts -->
        <section class="mb-12">
            <h2 class="text-3xl font-bold mb-8 text-gradient">
                <i class="fas fa-book-open mr-3"></i>基本概念
            </h2>
            
            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-arrow-right"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">正向代理</h3>
                    <p class="text-gray-600">客户端配置代理，代理服务器代表客户端访问外部网络资源。</p>
                </div>
                
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-arrow-left"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">反向代理</h3>
                    <p class="text-gray-600">客户端无需知道后端服务器的存在，所有请求都由反向代理服务器处理，反向代理服务器再将请求转发到内部的目标服务器。</p>
                </div>
            </div>
        </section>

        <div class="section-divider"></div>

        <!-- Features -->
        <section class="mb-12">
            <h2 class="text-3xl font-bold mb-8 text-gradient">
                <i class="fas fa-star mr-3"></i>核心特性
            </h2>
            
            <div class="grid md:grid-cols-2 lg:grid-cols-4 gap-6">
                <div class="bg-gradient-to-br from-purple-50 to-pink-50 rounded-xl p-6 card-hover">
                    <i class="fas fa-user-secret text-3xl text-purple-600 mb-4"></i>
                    <h4 class="font-bold mb-2">隐藏真实服务器</h4>
                    <p class="text-sm text-gray-600">客户端只知道反向代理服务器的IP地址，增强系统安全性。</p>
                </div>
                
                <div class="bg-gradient-to-br from-blue-50 to-cyan-50 rounded-xl p-6 card-hover">
                    <i class="fas fa-balance-scale-right text-3xl text-blue-600 mb-4"></i>
                    <h4 class="font-bold mb-2">负载均衡</h4>
                    <p class="text-sm text-gray-600">将请求分发到多个后端服务器，提高并发处理能力。</p>
                </div>
                
                <div class="bg-gradient-to-br from-green-50 to-emerald-50 rounded-xl p-6 card-hover">
                    <i class="fas fa-rocket text-3xl text-green-600 mb-4"></i>
                    <h4 class="font-bold mb-2">缓存与加速</h4>
                    <p class="text-sm text-gray-600">缓存静态内容，减少后端负载并提升响应速度。</p>
                </div>
                
                <div class="bg-gradient-to-br from-orange-50 to-yellow-50 rounded-xl p-6 card-hover">
                    <i class="fas fa-shield-alt text-3xl text-orange-600 mb-4"></i>
                    <h4 class="font-bold mb-2">安全隔离</h4>
                    <p class="text-sm text-gray-600">作为防火墙保护后端服务器免受直接访问。</p>
                </div>
            </div>
        </section>

        <div class="section-divider"></div>

        <!-- Use Cases -->
        <section class="mb-12">
            <h2 class="text-3xl font-bold mb-8 text-gradient">
                <i class="fas fa-puzzle-piece mr-3"></i>常见应用场景
            </h2>
            
            <div class="space-y-6">
                <!-- Load Balancing -->
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <h3 class="text-2xl font-bold mb-4 flex items-center">
                        <i class="fas fa-network-wired mr-3 text-purple-600"></i>
                        负载均衡
                    </h3>
                    <p class="text-gray-700 mb-4">Nginx能够将客户端请求分发到多个后端服务器，保证请求的均匀分布，提升系统的整体处理能力。</p>
                    
                    <div class="grid md:grid-cols-3 gap-4 mt-6">
                        <div class="bg-gray-50 rounded-lg p-4">
                            <h4 class="font-semibold mb-2">轮询（Round-robin）</h4>
                            <p class="text-sm text-gray-600">默认方式，按顺序轮流分发请求</p>
                        </div>
                        <div class="bg-gray-50 rounded-lg p-4">
                            <h4 class="font-semibold mb-2">最少连接</h4>
                            <p class="text-sm text-gray-600">分发给当前连接数最少的服务器</p>
                        </div>
                        <div class="bg-gray-50 rounded-lg p-4">
                            <h4 class="font-semibold mb-2">IP哈希</h4>
                            <p class="text-sm text-gray-600">根据客户端IP进行哈希分配</p>
                        </div>
                    </div>
                </div>

                <!-- Cache Acceleration -->
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <h3 class="text-2xl font-bold mb-4 flex items-center">
                        <i class="fas fa-bolt mr-3 text-yellow-600"></i>
                        缓存加速
                    </h3>
                    <p class="text-gray-700">Nginx可以缓存后端服务器的响应，减少后端负载并加快响应速度。静态内容能够被缓存并在后续请求中直接返回。</p>
                </div>

                <!-- SSL/TLS Termination -->
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <h3 class="text-2xl font-bold mb-4 flex items-center">
                        <i class="fas fa-lock mr-3 text-green-600"></i>
                        TLS/SSL终端代理
                    </h3>
                    <p class="text-gray-700">在Nginx处进行SSL/TLS协议的加密与解密，减轻后端服务器的负担，提升性能。</p>
                </div>

                <!-- WebSocket Proxy -->
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <h3 class="text-2xl font-bold mb-4 flex items-center">
                        <i class="fas fa-plug mr-3 text-blue-600"></i>
                        WebSocket代理
                    </h3>
                    <p class="text-gray-700">支持WebSocket协议的升级过程，适用于实时应用如即时聊天、实时数据推送等。